/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

typedef struct ListNode ListNode;

struct ListNode* reverseList(struct ListNode* head)
{
    if (!head)
        return head;

    ListNode* n1 = NULL, * n2 = head, * n3 = head;

    while (n3)
    {
        n3 = n2->next;
        n2->next = n1;
        n1 = n2;
        if (n3)
            n2 = n3;
    }

    return n2;
}